package ru.usu.gv.gui.analysis;

import ru.usu.gv.core.GraphCanvas;
import ru.usu.gv.graph.Graph;
import ru.usu.gv.uicomponents.UIGraph;

/**
 @author Sergey Pupyrev 
 12.04.2007
 */

public abstract class GraphAnalyzer implements IGraphAnalyzer
{
	private static final int EDGE_COUNT_LIMIT = 1000;
	private static final int VERTEX_COUNT_LIMIT = 100;

	private IGraphAnalysVisualizer _visualComponent;

	public GraphAnalyzer(IGraphAnalysVisualizer visualComponent)
	{
		_visualComponent = visualComponent;
	}

	public void doAnalyse()
	{
		UIGraph uiGraph = GraphCanvas.getInstance().getCurrentGraph();
		Graph graph = uiGraph.getGraph();

		if (graph.getSize() == 0 || graph.getSize() > VERTEX_COUNT_LIMIT || graph.getEdgeSize() > EDGE_COUNT_LIMIT)
		{
			_visualComponent.setValue(0);
			return;
		}

		double newValue = calculateAnalysValue();
		if (newValue > 1.0)
			newValue = 1.0;
		if (newValue < 0.0)
			newValue = 0.0;
		newValue = newValue * 100.0;
		_visualComponent.setValue((int) newValue);
	}

	protected abstract double calculateAnalysValue();
}
